<?xml version="1.0" encoding="utf-8"?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
	xmlns:tb="http://rotor.di.unipi.it/cisterni/lid/treebeard">
	<head>
		<title> Project Barbalbero: Twitter client </title>
		<link rel="stylesheet" href="twitter.css" type="text/css" />
		<script type="text/javascript" src="jquery.js"></script>
		<script type="text/javascript" src="XPath_client.js"></script>
		<script type="text/javascript" src="frameworkFunctions_client.js"></script>
		<script type="text/javascript">
			var all_tweets;
            
            function insertTweet(event) {
                //alert('mother');
                tweets_client[0].insertBefore(event.relatedNode,tweets_client[0].firstChild);
            }
            
			function OnLoad () {
                    
			    	var hypers = % .//#hypernode % //__selectElements(document, ".//hypernode"); //seleziona hypernodes locali 
					var tweets_client = % .//div[@id='tweets_cl'] %  //__selectElements(document, ".//div[@id='tweets_cl']"); //seleziona div tweets del client
					var tweets_server = $ hypers -> .//div[@id='tweet'] $ // __selectElements(hypers[0], ".//div[@id='tweet']"); //seleziona tweet remoti
				

					//Client registrato agli eventi di modifica del sottoalbero tweets_server del server
                    % [on DOMNodeInserted do insertTweet] hypers -> . %
				
					for (n in tweets_server){
						//alert(tweets_server[n]);
						tweets_client[0].insertBefore(tweets_server[n],tweets_client[0].firstChild);
					}
					
					//all_tweets = document.getElementById("tweets_cl");
					//alert("OnLoad :\n"+all_tweets.innerHTML);
			  }
			  
			  function AddTweet() {
					var msg = __selectElements(document, ".//textarea[@name='message']");
					var hypers = __selectElements(document, ".//hypernode");
					//all_tweets = document.getElementById("tweets_cl");
					//alert(all_tweets.outerHTML);
					__setContent(hypers[0], ".","<div id=\"tweet\">"+msg[0].value+"</div>"); 
					//alert('new tweet added');
			  }
		</script>
	</head>

	<body onload="OnLoad();">
		<div id="header">
			<h1>Barbalbero demo - twitter client</h1>
		</div>
		<div id="main">
			<h2 id="whatHappening">What's happening?</h2>
			<textarea id="message" name="message" cols="60" rows="3">Test message</textarea>
			<div>
				<button onclick="AddTweet()" id="tweetButton">Tweet</button>
			</div>
			<div id="tweets_cl">
			</div>
			<hypernode refname="reftweets">
		</div>
	</body>
</html>